package com.bnivideo.ui.reflection

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: jiming
 * Date: 11-7-29
 * Time: 下午2:17
 * To change this template use File | Settings | File Templates.
 */
class FieldSplitter {
    public Map split(String input) {
        Map<String, String> result = new LinkedHashMap<String, String>();
        String temp = input.replaceAll("(?s)\\/\\*.*?\\*\\/", "")
        temp = temp.replaceAll("<.+>", "")
        temp = temp.replaceAll("\\bprivate\\b", "");
        temp = temp.replaceAll("\\bprotected\\b", "");
        temp = temp.replaceAll("\\bpublic\\b", "");
        def items = temp.split("[;\\\n]");
        items.eachWithIndex { obj, i ->
             println i + ":" + obj;
        }

        items = items.grep {
            def line = it.trim();
            return !(line.size() < 2 || line.startsWith("//"));
        }

        for(String item: items) {
            item = item.trim();
            String[] itemArr = item.split("\\s+");
            if(itemArr.length != 2) throw new IllegalArgumentException("["+item+"] is not valid.");
            result.put(itemArr[1], itemArr[0]);
        }
        return result;
    }
}
